package  
{
	/**
	 * ...
	 * @author hp
	 */
	
	import flash.display.Sprite;
	import flash.events.*;
	import flash.display.Stage;
	
	public class Hero extends Sprite
	{
		var stageRef: Stage;
		var speed:Number = 2;
		
		public function Hero(stageRef: Stage): void 
		{	
			x = 20;
			y = 20;
			
			this.stageRef = stageRef;
			
			this.graphics.beginFill(0x00FF00, 1);
			this.graphics.drawCircle(x, y, 20);
			this.graphics.endFill();
			
			//addEventListener(Event.ENTER_FRAME, loop, false, 0, true);
			//addEventListener(MouseEvent.CLICK, mClick, false, 0, true);
		}
		
		private function loop(e:Event):void
		{
			var yDist:Number = stageRef.mouseY - y;
			var xDist:Number = stageRef.mouseX - x;
			
			if (Math.sqrt(yDist * yDist + xDist * xDist) < speed)
			{
				x = stageRef.mouseX;
				y = stageRef.mouseY;
			}
			else
			{
				var radian:Number = Math.atan2(yDist, xDist);
			
				x += Math.cos(radian) * speed;
				y += Math.sin(radian) * speed;	
				
				rotation = radian * 180 / Math.PI;
			}
		}
		
		public function move(x:Number, y:Number):void
		{
			this.x = x;
			this.y = y;
		}
		
	}

}